package com.zeta.plan.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class ResponseResult<T> {
    /**
     * 是否成功
     */
    private boolean success;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 消息
     */
    private String message;
    /**
     * 数据
     */
    private T data;

    public static <T> ResponseResult<T> ok(T t) {
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setSuccess(true)
                .setCode(ResultCode.OK)
                .setMessage("成功")
                .setData(t);
        return responseResult;
    }

    public static  ResponseResult<Void> ok() {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(true)
                .setCode(ResultCode.OK)
                .setMessage("成功");
        return responseResult;
    }

    public static ResponseResult<Void> internalServerError() {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.INTERNAL_SERVER_ERROR)
                .setMessage("服务器错误");
        return responseResult;
    }

    public static ResponseResult<Void> unauthorized() {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.UNAUTHORIZED)
                .setMessage("身份验证失败");
        return responseResult;
    }

    public static ResponseResult<Void> unauthorized(String msg) {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.UNAUTHORIZED)
                .setMessage(msg);
        return responseResult;
    }

    public static ResponseResult<Void> forbidden() {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.FORBIDDEN)
                .setMessage("服务器拒绝请求");
        return responseResult;
    }

    public static ResponseResult<Void> notFount() {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.NOT_FOUND)
                .setMessage("请求资源不存在");
        return responseResult;

    }

    public static ResponseResult<Void> error() {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.INTERNAL_SERVER_ERROR);
        return responseResult;
    }
    public static ResponseResult<Void> error(String msg) {
        ResponseResult<Void> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false)
                .setCode(ResultCode.INTERNAL_SERVER_ERROR)
                .setMessage(msg);
        return responseResult;
    }


}
